<?php
namespace app\admin\controller;

use think\Cache;
use think\Controller;
use think\Cookie;
use think\Db;
use think\Session;


class Index extends Common
{
    public function index()
    {
//        $name 所设置的缓存名字
//        $value 存入数据
//        Cache::set('chengjp', 'sadfsadhsaudhsaudhusahduashdusah');
//        echo  Cache::get('chengjp');

//        cache('hhhhh','sdhusahdusahudsahudhsaudhasdxd1111');
////        echo  Cache::get('hhhhh');
//        echo  cache('hhhhh');


//        redis
//        phpinfo();


        $ar = array(
            0 => 'jjjijijiji.png',
            1 => 'jjjijijiji.png',
            2 => 'jjjijijiji.png',
            3 => 'jjjijijiji.png',
            4 => 'jjjijijiji.png',
        );
        for($i = 0;$i<count($ar);$i++){
            $data = array(
                'u_id' => 11152,
                'url'  => $ar[$i],
                'time' => time()
            );
           Db::table('biaomin')->insert($data);
        }

        return $this->fetch('god');
    }
    public function login(){
        if (!empty($_POST)){
            $name=$_POST['username'];
            $password=$_POST['password'];
            $where=array(
                'name'=>$name,
            );
           $res= Db::table('admin')->where($where)->find();
            if ($res['name']==$name){
               if ($res['password']==$password){
                   Session::set('name',$name);
                   Session::set('password',$password);
                   Session::set('logintime',time());
                   Cookie::set('name',$name,40);
                   Cookie::set('password',$password,40);
                   $this->success('登录成功','admin/index/index');
               }
            }else{
                $this->error('用户不存在','admin/index/login');
            }
        }

        return $this->fetch('login');
    }
}
